@extends('layouts.default')
@section('css')
    <link rel="stylesheet" href="{{asset('admin-lte/plugins/datatables/dataTables.bootstrap4.css')}}">
    {{--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">--}}
@stop


<?php //var_dump($ruleModel->rule_type);exit;?>
@section('content')
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">优惠券管理 / <a class="text-primary" href="{{url('admin/coupon/rule')}}">优惠券规则列表</a></h3>
                </div>

                <div class="card-body">
                    @include('layouts.message')
                    <button class="btn btn-info btn-sm" style="margin-bottom:10px" onclick="location.href='{{url('admin/coupon/create_rule_form')}}'">添加规则</button>
                    <table id="example1" class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>操作</th>
                            <th>名称</th>
                            <th>描述</th>
                            <th>优惠券类型</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach ($list as $rule)
                            <tr>
                                <td>
                                    <button class="btn btn-sm btn-primary" onclick="location.href='{{url('admin/coupon/edit_rule_form',['rule_id'=>$rule['rule_id']])}}'">编辑</button>
                                    <button data-url="{{url('admin/coupon/delterule',['rule_id'=>$rule['rule_id']])}}" class="btn btn-sm btn-danger del-goods">删除</button>
                                </td>
                                <td>{{ $rule['title'] }}</td>
                                <td>{{ $rule['brief'] }}</td>
                                <td>{{ $ruleModel->rule_type[trim($rule['reduce_type'])] }}</td>
                            </tr>
                        @endforeach
                        </tbody>
                        <tfoot>
                        <tr>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                        </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>

@stop





@section('script')
    <script src="{{asset('admin-lte/plugins/datatables/jquery.dataTables.js')}}"></script>
    <script src="{{asset('admin-lte/plugins/datatables/dataTables.bootstrap4.js')}}"></script>
    {{--layer插件--}}
    <script src='{{asset("admin-lte/plugins/layer-v3.1.1/layer.js")}}' type="text/javascript"></script>
    <script>
        $(function () {
            $("#example1").DataTable({
                "language"  : {
                    url :'https://cdn.datatables.net/plug-ins/1.10.19/i18n/Chinese.json'
                },
                //启用或者禁用某一列的排序功能
                "columnDefs": [
                    { "orderable": false, "targets": 0 }
                ],

                buttons: [
                    {
                        text: 'Alert',
                        action: function ( e, dt, node, config ) {
                            alert( 'Activated!' );
                            this.disable(); // disable button
                        }
                    }
                ]
            });

        });

        $('.del-goods').click(function(e){
            layer.confirm('确认要删除该商品吗？',function(){
                location.href = $(e.target).data('url');
            })
        })


    </script>
@stop



